
export const state = () => ({
  orderBy: 'sale', // 根据什么字段排序
  query: {
    name: '',
    page: 1,
    size: 10
  },
  goodsInfo: { // 商品详情
    goodsImg: [],
    title: '',
    tags: [],
    discount: [],
    promotion: [],
    remarksNum: 0,
    setMeal: [],
    hot: [],
    goodsDetail: [],
    param: [],
    remarks: []
  },
  marketing: { // 营销
    carouselItems: [], // 轮播图
    activity: [] // 活动
  },
  computer: {}, // 电脑专栏
  eat: {}, // 爱吃专栏
  asItems: [], // 广告
  goodsList: [], // 商品列表
  recommend: [], // 推荐购买
  address: []
})

export const mutations = {
  // 设置请求信息
  SET_QUERY(state, query) {
    state.query = JSON.parse(JSON.stringify(query))
  },
  // 设置轮播图
  SET_CAROUSELITEMS_INFO(state, { carouselItems, activity }) {
    state.marketing.carouselItems = carouselItems
    state.marketing.activity = activity
  },

  // 设置电脑专栏数据
  SET_COMPUTER_INFO(state, computer) {
    state.computer = computer
  },

  // 设置爱吃专栏数据
  SET_EAT_INFO(state, eat) {
    state.eat = eat
  },

  // 设置商品列表(搜索)
  SET_GOODS_LIST(state, data) {
    state.goodsList = data.goodsList
    state.asItems = data.asItems
  },

  // 设置商品列表排序
  SET_GOODS_ORDER_BY(state, data) {
    state.orderBy = data
  },

  // 设置商品详细信息
  SET_GOODS_INFO(state, data) {
    state.goodsInfo = data
  },

  // 设置推荐信息
  SET_RECOMMEND_INFO(state, data) {
    state.recommend = data
  },

  // 设置收获地址
  SET_USER_ADDRESS(state, data) {
    state.address = data
  }
}

export const actions = {

// 获取轮播(营销)图片
  loadCarouselItems({ commit }) {
    return new Promise((resolve, reject) => {
      const data = {
        carouselItems: [
          '/img/nav/1.jpg',
          '/img/nav/2.jpg',
          '/img/nav/3.jpg',
          '/img/nav/4.jpg',
          '/img/nav/5.jpg'
        ],
        activity: [
          '/img/nav/nav_showimg1.jpg',
          '/img/nav/nav_showimg2.jpg'
        ]
      }
      commit('SET_CAROUSELITEMS_INFO', data)
    })
  },

  // 加载电脑专栏数据
  loadComputer({ commit }) {
    return new Promise((resolve, reject) => {
      const computer = {
        title: '电脑数码',
        link: ['电脑馆', '游戏极品', '装机大师', '职场焕新', '女神频道', '虚拟现实', '二合一平板', '电子教育', '万物周刊'],
        detail: [
          {
            bigImg: '/img/index/computer/item-computer-1.jpg',
            itemFour: [
              {
                title: '电脑馆',
                intro: '笔记本999元限量秒！',
                img: '/img/index/computer/item-computer-2.jpg'
              },
              {
                title: '外设装备',
                intro: '1000减618',
                img: '/img/index/computer/item-computer-1-3.jpg'
              },
              {
                title: '电脑配件',
                intro: '联合满减最高省618',
                img: '/img/index/computer/item-computer-1-4.jpg'
              },
              {
                title: '办公生活',
                intro: '5折神券 精品文具',
                img: '/img/index/computer/item-computer-1-5.jpg'
              }
            ],
            itemContent: [
              '/img/index/computer/item-computer-1-6.jpg',
              '/img/index/computer/item-computer-1-7.jpg',
              '/img/index/computer/item-computer-1-8.jpg'
            ]
          },
          {
            bigImg: '/img/index/computer/item-computer-2-1.jpg',
            itemFour: [
              {
                title: '平板电脑',
                intro: '爆款平板12期免息',
                img: '/img/index/computer/item-computer-2-2.jpg'
              },
              {
                title: '智能酷玩',
                intro: '抢999减666神券',
                img: '/img/index/computer/item-computer-2-3.jpg'
              },
              {
                title: '娱乐影音',
                intro: '大牌耳机低至5折',
                img: '/img/index/computer/item-computer-2-4.jpg'
              },
              {
                title: '摄影摄像',
                intro: '大牌相机5折抢',
                img: '/img/index/computer/item-computer-2-5.jpg'
              }
            ],
            itemContent: [
              '/img/index/computer/item-computer-2-6.jpg',
              '/img/index/computer/item-computer-2-7.jpg',
              '/img/index/computer/item-computer-2-8.jpg'
            ]
          }
        ]
      }
      commit('SET_COMPUTER_INFO', computer)
    })
  },

  // 加载爱吃专栏数据
  loadEat({ commit }) {
    return new Promise((resolve, reject) => {
      const eat = {
        title: '爱吃',
        link: ['休闲零食', '坚果', '牛奶', '饮料冲调', '食用油', '大米', '白酒', '红酒', '烧烤食材', '牛排', '樱桃'],
        detail: [
          {
            bigImg: '/img/index/eat/item-eat-1-1.jpg',
            itemFour: [
              {
                title: '粮油调味',
                intro: '买2免1',
                img: '/img/index/eat/item-eat-1-2.jpg'
              },
              {
                title: '饮料冲调',
                intro: '第二件半价',
                img: '/img/index/eat/item-eat-1-3.jpg'
              },
              {
                title: '休闲零食',
                intro: '满99减40',
                img: '/img/index/eat/item-eat-1-4.jpg'
              },
              {
                title: '中外名酒',
                intro: '满199减100',
                img: '/img/index/eat/item-eat-1-5.jpg'
              }
            ],
            itemContent: [
              '/img/index/eat/item-eat-1-6.jpg',
              '/img/index/eat/item-eat-1-7.jpg',
              '/img/index/eat/item-eat-1-8.jpg'
            ]
          },
          {
            bigImg: '/img/index/eat/item-eat-2-1.jpg',
            itemFour: [
              {
                title: '东家菜',
                intro: '丰富好味',
                img: '/img/index/eat/item-eat-2-2.jpg'
              },
              {
                title: '东家菜',
                intro: '丰富好味',
                img: '/img/index/eat/item-eat-2-2.jpg'
              },
              {
                title: '东家菜',
                intro: '丰富好味',
                img: '/img/index/eat/item-eat-2-2.jpg'
              },
              {
                title: '东家菜',
                intro: '丰富好味',
                img: '/img/index/eat/item-eat-2-2.jpg'
              }
            ],
            itemContent: [
              '/img/index/eat/item-eat-2-6.jpg',
              '/img/index/eat/item-eat-2-7.jpg',
              '/img/index/eat/item-eat-2-8.jpg'
            ]
          }
        ]
      }
      commit('SET_EAT_INFO', eat)
    })
  },

  // 请求获得商品详细信息
  loadGoodsInfo({ commit }) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const data = {
          goodsImg: [
            '/img/goodsDetail/item-detail-1.jpg',
            '/img/goodsDetail/item-detail-2.jpg',
            '/img/goodsDetail/item-detail-3.jpg',
            '/img/goodsDetail/item-detail-4.jpg'
          ],
          title: '苹果8/7手机壳iPhone7 Plus保护壳全包防摔磨砂硬外壳',
          tags: ['满69-20元', '关注产品★送钢化膜', 'BIT配次日达'],
          discount: ['满148减10', '满218减20', '满288减30'],
          promotion: ['跨店满减', '多买优惠'],
          remarksNum: 6000,
          setMeal: [
            [
              {
                img: '/img/goodsDetail/pack/1.jpg',
                intro: '4.7英寸-深邃蓝',
                price: 28.0
              },
              {
                img: '/img/goodsDetail/pack/2.jpg',
                intro: '4.7英寸-星空黑',
                price: 29.0
              },
              {
                img: '/img/goodsDetail/pack/3.jpg',
                intro: '5.5英寸-香槟金',
                price: 28.5
              }
            ],
            [
              {
                img: '/img/goodsDetail/pack/4.jpg',
                intro: '5.5英寸-玫瑰金',
                price: 32.0
              },
              {
                img: '/img/goodsDetail/pack/5.jpg',
                intro: '5.5英寸-深邃蓝',
                price: 32.0
              },
              {
                img: '/img/goodsDetail/pack/6.jpg',
                intro: '5.5英寸-星空黑',
                price: 35.0
              }
            ],
            [
              {
                img: '/img/goodsDetail/pack/7.jpg',
                intro: '4.7英寸-香槟金',
                price: 26.0
              },
              {
                img: '/img/goodsDetail/pack/8.jpg',
                intro: '4.7英寸-玫瑰金',
                price: 25.0
              },
              {
                img: '/img/goodsDetail/pack/9.jpg',
                intro: '4.7英寸-中国红',
                price: 28.0
              }
            ]
          ],
          hot: [
            {
              img: '/img/goodsDetail/hot/1.jpg',
              price: 28.0,
              sale: 165076
            },
            {
              img: '/img/goodsDetail/hot/2.jpg',
              price: 36.0,
              sale: 135078
            },
            {
              img: '/img/goodsDetail/hot/3.jpg',
              price: 38.0,
              sale: 105073
            },
            {
              img: '/img/goodsDetail/hot/4.jpg',
              price: 39.0,
              sale: 95079
            },
            {
              img: '/img/goodsDetail/hot/5.jpg',
              price: 25.0,
              sale: 5077
            },
            {
              img: '/img/goodsDetail/hot/6.jpg',
              price: 20.0,
              sale: 3077
            }
          ],
          goodsDetail: [
            '/img/goodsDetail/intro/1.jpg',
            '/img/goodsDetail/intro/2.jpg',
            '/img/goodsDetail/intro/3.jpg',
            '/img/goodsDetail/intro/4.jpg'
          ],
          param: [
            {
              title: '商品名称',
              content: 'iPhone 7手机壳'
            },
            {
              title: '商品编号',
              content: '10435663237'
            },
            {
              title: '店铺',
              content: 'Gavin Shop'
            },
            {
              title: '商品毛重',
              content: '100.00g'
            },
            {
              title: '商品产地',
              content: '中国大陆'
            },
            {
              title: '机型',
              content: 'iPhone 7'
            },
            {
              title: '材质',
              content: 'PC/塑料'
            },
            {
              title: '款式',
              content: '软壳'
            },
            {
              title: '适用人群',
              content: '通用'
            }
          ],
          remarks: {
            goodAnalyse: 90,
            remarksTags: ['颜色可人', '实惠优选', '严丝合缝', '极致轻薄', '质量没话说', '比定做还合适', '完美品质', '正品行货', '包装有档次', '不容易发热', '已经买第二个', '是全覆盖'],
            remarksNumDetail: [2000, 3000, 900, 1],
            detail: [
              {
                username: 'p****1',
                values: 3,
                content: '颜色很好看，质量也不错！，还送了个指环，想不到哦！',
                goods: '4.7英寸-深邃蓝',
                create_at: '2018-05-15 09:20'
              },
              {
                username: '13****1',
                values: 5,
                content: '手感没的说，是硬壳，后背带有磨砂手感。很不错，很喜欢，还加送了钢化膜，支架环，物超所值，准备再买一个。很满意。物流很快。很愉快的一次购物！',
                goods: '5.5英寸-玫瑰金',
                create_at: '2018-05-13 15:23'
              },
              {
                username: '3****z',
                values: 4.5,
                content: '相当轻薄，店家还送了一大堆配件，*元非常值得！',
                goods: '4.7英寸-玫瑰金',
                create_at: '2018-05-05 12:25'
              },
              {
                username: 'gd****c',
                values: 3.5,
                content: '就是我想要的手机壳，壳子很薄，手感不错，就像没装手机壳一样，想要裸机手感的赶快下手了。',
                goods: '4.7英寸-中国红',
                create_at: '2018-04-06 16:23'
              },
              {
                username: 'r****b',
                values: 4.5,
                content: '壳子还不错，送的膜也可以，不过还是感觉膜小了那么一点，屏幕没法完全覆盖。对了，壳子稍微有点硬，可能会伤漆，所以不要频繁取壳就好。',
                goods: '4.7英寸-中国红',
                create_at: '2018-03-15 19:24'
              },
              {
                username: 'd****e',
                values: 5,
                content: '磨砂的，相当漂亮，尺寸非常合适！精工细作！',
                goods: '5.5英寸-星空黑',
                create_at: '2018-03-10 10:13'
              }
            ]
          }
        }
        commit('SET_GOODS_INFO', data)
      }, 300)
    })
  },

  // 获取商品列表
  loadGoodsList({ commit }) {
    return new Promise((resolve, reject) => {
      setTimeout(() => {
        const data = {
          asItems: [
            {
              img: '/img/goodsList/item-as-img-1.jpg',
              price: 39.9,
              intro: 'SKSK 苹果7/7plus手机壳 iPhone 7 Plus保护套全包硬',
              num: 3140,
              sale: 9000
            },
            {
              img: '/img/goodsList/item-as-img-2.jpg',
              price: 36.6,
              intro: '狮普 苹果7/7 Plus手机壳 电镀 超薄 全包 防摔 保护外',
              num: 6160,
              sale: 8900
            },
            {
              img: '/img/goodsList/item-as-img-1.jpg',
              price: 38.6,
              intro: 'SKSK 苹果7/7plus手机壳 iPhone 7 Plus保护套全包硬',
              num: 9160,
              sale: 8800
            },
            {
              img: '/img/goodsList/item-as-img-2.jpg',
              price: 35.6,
              intro: '狮普 苹果7/7 Plus手机壳 电镀 超薄 全包 防摔 保护外',
              num: 6160,
              sale: 7990
            },
            {
              img: '/img/goodsList/item-as-img-1.jpg',
              price: 38.6,
              intro: 'SKSK 苹果7/7plus手机壳 iPhone 7 Plus保护套全包硬',
              num: 9160,
              sale: 7600
            },
            {
              img: '/img/goodsList/item-as-img-2.jpg',
              price: 35.6,
              intro: '狮普 苹果7/7 Plus手机壳 电镀 超薄 全包 防摔 保护外',
              num: 6160,
              sale: 6900
            }
          ],
          goodsList: [
            {
              img: '/img/goodsList/item-show-1.jpg',
              price: 36.60,
              intro: 'SKSK 苹果7/7plus手机壳 iPhone 7 Plus保护套全包硬壳男女磨砂防摔 火影红(苹',
              remarks: 6160,
              shopName: '元亨利配件专营店',
              sale: 9900
            },
            {
              img: '/img/goodsList/item-show-2.jpg',
              price: 28.00,
              intro: '蒙奇奇 苹果6s手机壳磨砂防摔保护套 适用于iphone6/6s/6sPlus/6plus 6/6s 4.7英',
              remarks: 3000,
              shopName: 'monqiqi旗舰店',
              sale: 9600
            },
            {
              img: '/img/goodsList/item-show-3.jpg',
              price: 15.00,
              intro: 'BIAZE 苹果6/6s手机壳 苹果iphone6s 4.7英寸透明手机套 清爽系列',
              remarks: 2800,
              shopName: 'BIAZE官方旗舰店',
              sale: 8900
            },
            {
              img: '/img/goodsList/item-show-4.jpg',
              price: 29.90,
              intro: '慕臣 苹果6s手机壳全包防摔磨砂软保护套男女 适用于iPhone6splus',
              remarks: 9000,
              shopName: '歌乐力手配专营店',
              sale: 8600
            },
            {
              img: '/img/goodsList/item-show-5.jpg',
              price: 15.00,
              intro: 'BIAZE 苹果6/6s手机壳 苹果iphone6s 4.7英寸透明手机套 清爽系列',
              remarks: 6160,
              shopName: 'BIAZE官方旗舰店',
              sale: 8560
            },
            {
              img: '/img/goodsList/item-show-6.jpg',
              price: 28.00,
              intro: '慕臣 苹果6s手机壳全包防摔磨砂软保护套男女 适用于iPhone6splus',
              remarks: 9006,
              shopName: '歌乐力手配专营店',
              sale: 8530
            },
            {
              img: '/img/goodsList/item-show-7.jpg',
              price: 15.00,
              intro: 'BIAZE 苹果6/6s手机壳 苹果iphone6s 4.7英寸透明手机套 清爽系列',
              remarks: 8666,
              shopName: 'BIAZE官方旗舰店',
              sale: 8360
            },
            {
              img: '/img/goodsList/item-show-8.jpg',
              price: 29.90,
              intro: '慕臣 苹果6s手机壳全包防摔磨砂软保护套男女 适用于iPhone6splus',
              remarks: 6080,
              shopName: '歌乐力手配专营店',
              sale: 7560
            },
            {
              img: '/img/goodsList/item-show-1.jpg',
              price: 36.60,
              intro: 'SKSK 苹果7/7plus手机壳 iPhone 7 Plus保护套全包硬壳男女磨砂防摔 火影红(苹',
              remarks: 6160,
              shopName: '元亨利配件专营店',
              sale: 7360
            },
            {
              img: '/img/goodsList/item-show-2.jpg',
              price: 28.00,
              intro: '蒙奇奇 苹果6s手机壳磨砂防摔保护套 适用于iphone6/6s/6sPlus/6plus 6/6s 4.7英',
              remarks: 3000,
              shopName: 'monqiqi旗舰店',
              sale: 6960
            },
            {
              img: '/img/goodsList/item-show-3.jpg',
              price: 15.00,
              intro: 'BIAZE 苹果6/6s手机壳 苹果iphone6s 4.7英寸透明手机套 清爽系列',
              remarks: 2800,
              shopName: 'BIAZE官方旗舰店',
              sale: 6560
            },
            {
              img: '/img/goodsList/item-show-4.jpg',
              price: 29.90,
              intro: '慕臣 苹果6s手机壳全包防摔磨砂软保护套男女 适用于iPhone6splus',
              remarks: 9000,
              shopName: '歌乐力手配专营店',
              sale: 6360
            },
            {
              img: '/img/goodsList/item-show-5.jpg',
              price: 15.00,
              intro: 'BIAZE 苹果6/6s手机壳 苹果iphone6s 4.7英寸透明手机套 清爽系列',
              remarks: 6160,
              shopName: 'BIAZE官方旗舰店',
              sale: 5530
            },
            {
              img: '/img/goodsList/item-show-6.jpg',
              price: 28.00,
              intro: '慕臣 苹果6s手机壳全包防摔磨砂软保护套男女 适用于iPhone6splus',
              remarks: 9006,
              shopName: '歌乐力手配专营店',
              sale: 5560
            },
            {
              img: '/img/goodsList/item-show-7.jpg',
              price: 15.00,
              intro: 'BIAZE 苹果6/6s手机壳 苹果iphone6s 4.7英寸透明手机套 清爽系列',
              remarks: 8666,
              shopName: 'BIAZE官方旗舰店',
              sale: 5260
            },
            {
              img: '/img/goodsList/item-show-8.jpg',
              price: 29.90,
              intro: '慕臣 苹果6s手机壳全包防摔磨砂软保护套男女 适用于iPhone6splus',
              remarks: 6080,
              shopName: '歌乐力手配专营店',
              sale: 3560
            }
          ]
        }
        commit('SET_GOODS_LIST', data)
      })
    })
  },

  // 获取用户推荐
  loadRecommend({ commit }) {
    return new Promise((resolve, reject) => {
      const data = [
        [
          {
            img: '/img/otherBuy/1.jpg',
            intro: 'iPhone7/6s/8钢化膜苹果7Plus全屏全覆盖3D抗蓝',
            price: 29.00
          },
          {
            img: '/img/otherBuy/2.jpg',
            intro: '苹果数据线 苹果iPhoneX/6s/7plus/8充电线',
            price: 36.00
          },
          {
            img: '/img/otherBuy/3.jpg',
            intro: '苹果8/7/6/6s钢化膜 iphone8/7/6s/6钢化玻璃',
            price: 19.00
          },
          {
            img: '/img/otherBuy/4.jpg',
            intro: 'iPhone6s/7钢化膜苹果8 Plus手机膜抗蓝光非全屏',
            price: 28.00
          }
        ],
        [
          {
            img: '/img/otherBuy/5.jpg',
            intro: '苹果6s手机壳iPhone6s Plus保护壳防摔全',
            price: 28.00
          },
          {
            img: '/img/otherBuy/6.jpg',
            intro: 'iPhone7/8手机壳手机套防摔磨砂保护壳星空黑☆全包保护',
            price: 30.00
          },
          {
            img: '/img/otherBuy/7.jpg',
            intro: '数据线 适用于苹果iPhone 6s/6plus/7plus/8/X',
            price: 18.00
          },
          {
            img: '/img/otherBuy/8.jpg',
            intro: 'iPhone8/7/6S/6钢化膜 苹果8/7/6s/6玻璃膜 手机高',
            price: 15.00
          }
        ]
      ]
      commit('SET_RECOMMEND_INFO', data)
    })
  },

  loadAddress({ commit }) {
    return new Promise((resolve, reject) => {
      const address = [
        {
          addressId: '123456',
          name: 'Gavin',
          province: '广东省',
          city: '广州市',
          area: '天河区',
          address: '燕岭路633号',
          phone: '152****0609',
          postalcode: '510000'
        },
        {
          addressId: '123458',
          name: 'Kevin',
          province: '上海市',
          city: '上海市',
          area: '浦东新区',
          address: '沙新镇',
          phone: '158****0888',
          postalcode: '200120'
        }
      ]
      commit('SET_USER_ADDRESS', address)
    })
  }
}
